package com.bws;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.junit.Before;
import org.junit.Test;

public class HBaseTest {
    //表的管理类
    HBaseAdmin admin = null;
    //数据的管理类
    HTable table = null;
    //表名
    String tm = "phone";

    /**
     * 完成初始化功能
     * @throws Exception
     */
    @Before
    public void init() throws Exception{
        Configuration conf = new Configuration();
        conf.set("hbase.zookeeper.quorum", "192.168.79.7");
        admin = new HBaseAdmin(conf);
        table = new HTable(conf,tm.getBytes());
    }

    /**
     * 创建表
     * @throws Exception
     */

    @Test
    public void createTable() throws Exception{
        //表的描述类
        HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tm));
        //列族的描述类
        HColumnDescriptor family = new HColumnDescriptor("cf".getBytes());
        desc.addFamily(family);
        if(admin.tableExists(tm)){
            admin.disableTable(tm);
            admin.deleteTable(tm);
        }
        admin.createTable(desc);
    }

}
